// 国际化
import { createI18n, useI18n } from "vue-i18n";
import Store from "@/store";
// my
import * as zhLocale from "./locales/zh-CN/zh.json";
import * as enLocale from "./locales/en-US/en.json";
import Lang from "./components/Lang.vue";

const messages = {
	"zh-cn": zhLocale,
	en: enLocale,
};

const i18n = createI18n({
	// something vue-i18n options here ...
	locale: Store.getters["setting/lang"],
	fallbackLocale: "en",
	messages: messages,
});

const changeIndex = (list: string[]) => {
	list.splice(
		list.findIndex(item => item === "zh-cn"),
		1,
	);
	list.splice(
		list.findIndex(item => item === "en"),
		1,
	);
	list.unshift("en");
	list.unshift("zh-cn");
	return list;
};

// i18n 语言列表
export const availableLocales = changeIndex(i18n.global.availableLocales);

export interface LangSetting extends StringIndex {
	readonly "zh-cn": "中 文";
	readonly en: "English";
}
// 对于语言
export const langSetting: LangSetting = {
	"zh-cn": "中 文",
	en: "English",
};

export { useI18n, Lang };

export default i18n;
